import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'

const router2 = createRouter({
  linkActiveClass: 'activeTab',
  history: createWebHashHistory(),
  routes: [
    {
      path: '/myhome',
      component: import('../views/RouterHomeView.vue'),
    },
    {
      path: '/myabout',
      component: import('../views/RouterAboutView.vue'),
      children: [
        { path: 'about1', component: import('../views/RouterPages/About1.vue') },
        { path: 'about2', component: import('../views/RouterPages/About2.vue') },
      ],
    },
    {
      path: '/mymovie',

      component: import('../views/RouterMovieView.vue'),
      children: [
        // {
        //   path: ':id',
        //   component: import('../views/RouterPages/MovieDetail.vue'),
        //   props: true,
        // },
        {
          path: ':id/:name?',
          name: 'movieDetail',
          component: import('../views/RouterPages/MovieDetail.vue'),
          props: true,
        },
      ],
    },
    {
      name: 'login',
      path: '/login',
      component: import('../views/LoginView.vue'),
    },
  ],
})
router2.beforeEach((to, from, next) => {
  const isLogin = false
  if (to.name == 'movieDetail') {
    if (!isLogin) {
      next({ name: 'login' })
    } else {
      next()
    }
  } else {
    next()
  }
})
export default router2
